package com.dc.trans.steps.notesnotice;

import java.util.List;
import java.util.Map;

import org.pentaho.di.core.CheckResultInterface;
import org.pentaho.di.core.Counter;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.repository.ObjectId;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStepMeta;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepIOMeta;
import org.pentaho.di.trans.step.StepIOMetaInterface;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.w3c.dom.Node;


/**
* @ClassName: NoticeMeta
* @Description: TODO
* @author zhangbinp
* @date Aug 24, 2011 2:06:05 PM
*/
public class NotesNoticeMeta extends BaseStepMeta implements StepMetaInterface{

	private String url;
	private String name;
	private boolean ignoreErrors = true;
	
	
	/**
     * @param ignoreErrors The ignore errors flag to set.
     */
    public void setIgnoreErrors(boolean ignoreErrors)
    {
        this.ignoreErrors = ignoreErrors;
    }
    
    /**
     * @return Returns the ignore errors flag.
     */
    public boolean ignoreErrors()
    {
        return ignoreErrors;
    }
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public void check(List<CheckResultInterface> remarks, TransMeta transMeta,
			StepMeta stepMeta, RowMetaInterface prev, String[] input,
			String[] output, RowMetaInterface info) {
		// TODO Auto-generated method stub
		
	}

	public StepInterface getStep(StepMeta stepMeta,
			StepDataInterface stepDataInterface, int copyNr,
			TransMeta transMeta, Trans trans) {
		// TODO Auto-generated method stub
		return new NotesNotice(stepMeta, stepDataInterface, copyNr, transMeta, trans);
	}

	public StepDataInterface getStepData() {
		// TODO Auto-generated method stub
		return new NotesNoticeData();
	}

	public void loadXML(Node stepnode, List<DatabaseMeta> databases,
			Map<String, Counter> counters) throws KettleXMLException {
		try
		{
			ignoreErrors   = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "ignore_errors"));
			url     = XMLHandler.getTagValue(stepnode, "url");
		}
		catch(Exception e)
		{
			throw new KettleXMLException("Unable to load step info from XML", e);
		}
	}

	public void readRep(Repository rep, ObjectId id_step,
			List<DatabaseMeta> databases, Map<String, Counter> counters)
			throws KettleException {
		ignoreErrors     =      rep.getStepAttributeBoolean(id_step, "ignore_errors");
		url         =   rep.getStepAttributeString(id_step, "url");
	}

	public void saveRep(Repository rep, ObjectId id_transformation,
			ObjectId id_step) throws KettleException {
		rep.saveStepAttribute(id_transformation, id_step, "ignore_errors",   ignoreErrors);
		rep.saveStepAttribute(id_transformation, id_step, "url",   url);
	}

	public void setDefault() {
		
	}
	public String getXML()
	{
		StringBuilder retval=new StringBuilder();
		
		retval.append("    "+XMLHandler.addTagValue("ignore_errors",  ignoreErrors));
		retval.append("    "+XMLHandler.addTagValue("url",  url));

		return retval.toString();
	}

	@Override
	public StepIOMetaInterface getStepIOMeta() {
    	return new StepIOMeta(true, false, true, false, false, false);
    }
}
